package com.mall.order.biz.convert;

import com.mall.commons.result.AbstractRequest;
import com.mall.commons.result.AbstractResponse;
import com.mall.order.biz.context.CancelOrderContext_X;
import com.mall.order.biz.context.TransHandlerContext;
import com.mall.order.constant.OrderRetCode;
import com.mall.order.dto.CancelOrderRequest;
import com.mall.order.dto.CancelOrderResponse;

/**
 * @author XuBang
 * @TODO:  自定义
 * @date 2021/11/2$
 * @trainOfthought:
 */
public class CancelOrderConverter implements TransConvert{

    /**
     * 将request转化为context
     * @param req
     * @param context
     * @return
     */
    @Override
    public TransHandlerContext convertRequest2Ctx(AbstractRequest req, TransHandlerContext context) {
        CancelOrderRequest cancelOrderRequest = (CancelOrderRequest)req;
        CancelOrderContext_X cancelOrderContext_x = (CancelOrderContext_X) context;

        //将request中唯一的orderid交给context
        cancelOrderContext_x.setOrderId(cancelOrderRequest.getOrderId());

        return cancelOrderContext_x;
    }

    /**
     * 将context封装成response
     * @param ctx
     * @return
     */
    @Override
    public AbstractResponse convertCtx2Respond(TransHandlerContext ctx) {
        CancelOrderContext_X cancelOrderContext_x = (CancelOrderContext_X) ctx;
        CancelOrderResponse response = new CancelOrderResponse();

//        response.setResult("成功啦");
        response.setCode(OrderRetCode.SUCCESS.getCode());
        response.setMsg(OrderRetCode.SUCCESS.getMessage());
        return response;
    }
}
